#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N = 5e5 + 50;

struct ios {
    inline char read(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }

    template <typename _Tp> inline ios & operator >> (_Tp&x){
        static char c11,boo;
        for(c11=read(),boo=0;!isdigit(c11);c11=read()){
            if(c11==-1)return *this;
            boo|=c11=='-';
        }
        for(x=0;isdigit(c11);c11=read())x=x*10+(c11^'0');
        boo&&(x=-x);
        return *this;
    }

    int read(char *s) {
        int len = 0;
        char ch;
        for (ch=read(); ch=='\n' || ch == ' '; ch=read());
        if (ch == -1) {
            s[len] = 0;
            return -1;
        }
        for (; ch!='\n' && ch != ' ' && ch != -1;ch=read())
            s[len++] = ch;
        s[len] = 0;
        return len;
    }
} io;


#define P _P

struct P {
    int first, second;
    P (int first=0, int second=0):first(first), second(second){};
    bool operator < (const P &other) const { return first < other.first;}
};

inline bool cmp(const P &a, const P &b) {
    return a.first < b.first;
}


int disc[N], dcnt;


struct segT
{
    set<int> dat[(1<<20) + 50];
    int nn;

    void init(int n)
    {
        nn = 1;
        while (nn < n)
            nn <<= 1;
    }

    void upt(int i, int x)
    {
        i += nn - 1;
        for (; i; i >>= 1)
        {
            dat[i].insert(x);
        }
    }

    void del(int i, int x) {
        i += nn - 1;
        for (; i; i>>=1) {
            dat[i].erase(x);
        }
    }

    int L, R;
    set<int> q(int l, int r, int rt)
    {
        if (L <= l && r <= R)
        {
            return dat[rt];
        }
        int m = (l + r) >> 1;
        set<int> v1, v2, res;
        if (L <= m)
            v1 = q(l, m, rt << 1);
        if (m + 1 <= R)
            v2 = q(m + 1, r, rt << 1 | 1);
        for (int x : v1)
            res.insert(x);
        for (int x : v2)
            res.insert(x);
        return res;
    }

    inline set<int> q(int l, int r)
    {
        L = l;
        R = r;
        return q(1, nn, 1);
    }
} s;

struct dsu
{
    int f[500000 + 50];
    int n;
    void init(int n)
    {
        this->n = n;
        for (int i = 0; i <= n; ++i)
            f[i] = i;
    }
    int find(int x)
    {
        return x == f[x] ? x : (f[x] = find(f[x]));
    }
    inline void connect(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x < y)
            swap(x, y);
        f[x] = y;
    }
    inline bool test(int x, int y) { return find(x) == find(y); }
} d;

int n, t;
P a[500000 + 50];

P e[500000 + 50];
int ecnt;

set<P> S;

int main(int argc, char const *argv[])
{
    io >> n ;
    for (int i = 0; i < n; ++i)
        io >> a[i].first >> a[i].second;
    for (int i=0; i<n; ++i)
        disc[dcnt++] = a[i].second;
    sort(disc, disc+dcnt);
    for (int i=0; i<n; ++i)  a[i].second = lower_bound(disc, disc+dcnt, a[i].second) - disc + 1;
    assert(dcnt == n);
    d.init(n);
    sort(a, a + n);
    ecnt = 0;
    // for (int i=0; i<n; ++i) {
    //     printf("%d %d\n", i, a[i].second);
    // }
    for (int i = 0; i < n; ++i)
    {
        while (!S.empty() && disc[S.begin()->first-1] < a[i].first) {
            // int x = S.begin()->second;
            // printf("removed %d %d\n", a[x].second, x);
            S.erase(S.begin());
        }
        for (auto x : S) {
            if (x.first < a[i].second) {
                e[ecnt++] = P(i, x.second);
                // printf("%d %d\n", i, x.second);
                if (ecnt == n) break;
            } else break;
        }
        if (ecnt == n) break;
        S.emplace(a[i].second, i);
    }
    if (ecnt != n - 1)
    {
        puts("NO");
        return 0;
    }
    bool suc = true;
    for (int i = 0; i < n - 1; ++i)
    {
        int x = e[i].first, y = e[i].second;
        if (d.test(x, y))
        {
            suc = false;
            break;
        }
        d.connect(x, y);
    }
    printf("%s\n", suc ? "YES" : "NO");
    return 0;
}